﻿@model List<BackupModel>
<style>
    .table>tbody>tr>td { vertical-align: middle!important; }
</style>
<div class="page">
    <div class="box" style="width:100%;padding:10px;margin:0 auto;max-width:860px;" id="webbackup">
        <div class="box-header" style="padding-bottom:10px">
            <h3>备份列表</h3>
            <div class="box-tools">
                <button onclick="startBackup()" class="am-btn am-btn-info pull-right">开始备份</button>
            </div>
        </div>
        <div class="box-body no-padding">
            <table class="am-table">
                <thead>
                    <tr>
                        <td style="width:200px">文件名</td>
                        <td style="width:200px">创建时间</td>
                        <td style="width:200px">操作</td>
                    </tr>
                </thead>
                <tbody>
                    @if (Model.Count > 0)
            {
                foreach (var item in Model)
                {
                            <tr>
                                <td><a href="@item.FileUrl@item.FileName" target="_blank"><i class="am-icon-cloud-download"></i> @item.FileName</a></td>
                                <td>@item.Date</td>
                                <td style="text-align:center">
                                    <a href="@item.FileUrl@item.FileName" target="_blank" class="am-btn am-btn-primary">下载备份</a>
                                    <button class="am-btn am-btn-danger" onclick="delBackup('@item.FileName')" style="margin-left:20px">删除备份</button>
                                </td>
                            </tr>
                        }
                    }
                    else
                    {
                        <tr><td colspan="3"><h3 style="text-align:center;color:#BBB">暂时备份</h3></td></tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript">
    function reload() {
        pagevm.load('@ViewBag.GoUrl');
    }
    function startBackup() {
        var oBtn = $(window.event.target);
        oBtn.text("正在备份...").attr('disabled', true);
        $.post('@ViewBag.DoUrl', function (result) {
            oBtn.text('开始备份').attr('disabled', false);
            if (result.succ) {
                location.href = result.data;
                reload();
            } else {
                alert(result.data);
            }
        });
    }
    function delBackup(file) {
        if (!confirm("确定删除备份文件【" + file + "】？"))
            return false;
        $.post('@ViewBag.DelUrl', { fileName: file }, function (result) {
            if (result.succ) {
                alert("删除成功！");
                reload();
            } else {
                alert(result.data);
            }
        });
        return false;
    }
</script>